package com.gexin.controller.demo;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipOutputStream;

import com.gexin.common.utils.MessageUtils;
import com.gexin.common.utils.OtherUtil;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.AutoBindRoutes;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import org.apache.http.HttpResponse;

import javax.servlet.http.HttpServletResponse;

@ControllerBind(controllerKey = "/qy/test",viewPath="jsp/demo/")
public class QYTestController extends Controller {
	public static void main(String[] args) {
		System.err.println(PathKit.getRootClassPath()+File.separator+"weixin"+File.separator+"cer");
		System.err.println(PathKit.getWebRootPath());

	}

	public void yzm(){
		Date date = new Date();
		Calendar instance = Calendar.getInstance();
		instance.setTime(date);
		instance.add(Calendar.DAY_OF_MONTH, -3759);
		Date time = instance.getTime();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd" );
		String format = simpleDateFormat.format(time);
		System.out.println(format);

//
		PropKit.use("config.properties");
		renderJson(MessageUtils.sendTemplateSMS("18616372930", MessageUtils.loginId, new String[]{"599688","十分钟"}));
	}

	public void index(){
	    AutoBindRoutes routes = new AutoBindRoutes();
	    routes.config();
	    renderText("ok");
		//redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc696acc8af128327&redirect_uri=http://wxtest.shandian001.com/qy/test/code&response_type=code&scope=SCOPE&state=STATE#wechat_redirect");
	}

	public void code1(){
		// 设置响应头，控制浏览器下载该文件
		try {

			HttpServletResponse response = getResponse();
			// 创建输出流

			List<String> urls = new ArrayList<>();
			urls.add("http://cdn.gexinit.com/156966460677202.jpg");
			urls.add("http://cdn.gexinit.com/156966461229704.jpg");
			urls.add("http://cdn.gexinit.com/156966460705003.jpg");
			//获取所有图片url
			boolean rst = OtherUtil.downloadToZip(urls,response,"图片.zip");


		} catch (IOException e) {
			e.printStackTrace();
		}

		renderNull();
	}
	public void code(){
		renderText("success");
	}
}
